﻿@using thousandClear.Areas.Admin.Models;
@model List<AngentModel>
@{
    ViewBag.Title = "地区管理";
    Layout = "~/Areas/Admin/Views/Shared/_Admin.cshtml";
}

<div id="app">
    <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">后台管理</strong> / <small>@ViewBag.Title</small></div>
    </div>

    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    @if (ViewBag.level != "2")
                    {
                        <a href="~/admin/Agent/add" class="am-btn am-btn-primary"><span class="am-icon-plus"></span> 新增地区</a>
                    }
                </div>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-2">
            <div class="am-form-group">
                <label>省市区：</label>
                <select v-model="level">
                    <option value="">全部</option>
                    <option value="1">省</option>
                    <option value="2">市</option>
                    <option value="3">区</option>
                </select>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-12">
            <button class="am-btn am-btn-primary" v-on:click="search">查询</button>
        </div>

        <div class="am-g">
            <div class="am-u-sm-12">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                        <tr>
                            <th>编号</th>
                            <th>行政等级</th>
                            <th>地区名</th>
                            <th>所属区域</th>
                            <th>查看详情</th>
                        </tr>
                    </thead>
                    <tbody>

                        @foreach (AngentModel item in Model)
                        {
                            <tr>
                                <td>@item.DATID</td>
                                <td>
                                    @if (item.datLevel == 1)
                                    {
                                        <span>省</span>
                                    }
                                    @if (item.datLevel == 2)
                                    {
                                        <span>市</span>
                                    }
                                    @if (item.datLevel == 3)
                                    {
                                        <span>区</span>
                                    }
                                </td>
                                <td>@item.datDesc</td>
                                <td>@item.datDescH</td>
                                <td>
                                    @if (ViewBag.level != "2")
                                    {
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a href="~/admin/Agent/Edit?id=@item.DATID" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only"><span class="am-icon-edit"></span> 修改</a>
                                            </div>
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a v-on:click="remove(@item.DATID)" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only"><span class="am-icon-edit"></span> 删除</a>
                                            </div>
                                        </div>
                                    }
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                <div class="am-cf">
                    &nbsp;&nbsp;共 {{totalCount}} 条记录, 每页 {{pageCount}} 条记录
                    <div class="am-fr">
                        <ul class="am-pagination">
                            <li style="width: 60px">
                                <input class="am-form-field" style="text-align:center" type="text" v-model="gotoPage">

                            </li>
                            <li><a href="#" v-on:click="goto">GoTo &raquo;</a></li>
                            <li><a href="#" v-on:click="prev">&laquo; Prev</a></li>
                            <li><span>{{currentPage}}/{{totalPage}}</span></li>
                            <li><a href="#" v-on:click="next">Next &raquo;</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section Scripts{
    <script>
        var model = new Vue({
            el: '#app',
            data: {
                totalCount: @ViewBag.TotalCount,
                currentPage: @ViewBag.CurrentPage,
                pageCount: @ViewBag.PageCount,
                gotoPage: @ViewBag.CurrentPage,
                totalPage: @ViewBag.TotalPage,
                level:'@ViewBag.level'
            },
            methods: {
                prev: function() {
                    var self = this;
                    if (self.currentPage <= 1)
                        return;

                    self.currentPage -= 1;
                    self.load();
                },
                next: function() {
                    var self = this;

                    if (self.currentPage >= self.totalPage)
                        return;

                    self.currentPage += 1;

                    self.load();
                },
                goto: function() {
                    var self = this;
                    self.currentPage = self.gotoPage;
                    self.load();
                },
                search: function() {
                    var self = this;
                    self.currentPage = 1;
                    self.load();
                },
                load: function() {
                    var self = this;
                    window.location.href = "../admin/Agent?page=" + self.currentPage + "&count=" + self.pageCount + "&level=" + self.level;
                },
                remove: function (idx) {
                    var self = this;
                    var c = confirm('确认要删除吗?');
                    if (c) {
                        $.ajax({
                            type: "get",
                            url: "Agent/remove/"+idx,
                            contentType: "application/json",
                            success: function (data) {
                                alert("删除成功");
                                window.location.reload();
                            }

                        })


                    }
                    else {
                        return;
                    }


                }

            }
        });

        $('.admin-sidebar-Agent').addClass('current');
    </script>
}

